<?php
class SaleItem extends AppModel {
    var $name = 'SaleItem';

    public function listing () {

    } // listing

    public function orderList ($sale_id) {
        $sql  = 'SELECT s.`product_code`, s.`quantity`, p.`name` FROM `sale_items` AS s ' .
                'INNER JOIN `products` AS p ' .
                'ON s.`product_id`=p.`id` ' .
                'WHERE s.`sale_id`='.$sale_id.' ' .
                'ORDER BY s.`id` ASC';
        $data = $this->query($sql);
        $resp = array();

        if (count($data) == 0) {
            return 0;
        }

        foreach ($data as $d) {
            $resp[] = $d['s']['product_code'].' - '.$d['p']['name'].' x '.$d['s']['quantity'];
        }

        return $resp;
    } // orderList
} // SaleItem
?>